package com.usian.wemedia.controller;

import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.usian.api.admin.WmUserControllerApi;
import com.usian.model.common.dtos.ResponseResult;
import com.usian.model.media.pojos.WmUser;
import com.usian.wemedia.service.WmUserService;
import com.usian.wemedia.service.impl.WmUserServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/v1/user")
public class WmUserController implements WmUserControllerApi {
    @Autowired
    private WmUserServiceImpl service;
    @PostMapping("/save")
    @Override
    public  ResponseResult save(@RequestBody WmUser dto){
       if (dto==null)return service.errorParam;
        service.save(dto);
        return ResponseResult.okResult(dto);
    }

    @Override
    @GetMapping("findByName/{name}")
    public WmUser findByName(@PathVariable String name) {
     return service.getOne(Wrappers.<WmUser>lambdaQuery().eq(StringUtils.isNotEmpty(name), WmUser::getName, name));
    }

    @PostMapping("updateAuthorId")
    public  ResponseResult<WmUser> updateAuthorId(@RequestBody  WmUser wmUser){
        if (wmUser==null)return   service.errorParam;
        service.updateById(wmUser);
        return service.success;

    }

}
